package com.northpool.operator.common.scene;

import cn.hutool.core.util.StrUtil;
import com.northpool.operator.annotation.InputParam;
import com.northpool.operator.annotation.InputParams;
import com.northpool.operator.annotation.OperatorInfo;
import com.northpool.operator.annotation.OutputParam;
import com.northpool.operator.annotation.OutputParams;
import com.northpool.operator.common.algorithm.OperatorTestBuild;
import com.northpool.operator.common.algorithm.TestParamBuilder;
import com.northpool.operator.param.ParamTool;
import com.northpool.operator.utils.StpOperatorHelper;

@OperatorInfo(
        ref = "sceneOutOperator",
        name = "结果输出",
        version = "矢量服务",
        description = "输出空服的矢量服务地址"
)
@OutputParams({
        @OutputParam(ref = "vmap_url", name = "矢量瓦片服务底图地址", desc = "矢量瓦片服务底图地址"),
        @OutputParam(ref = "bbox", name = "四至范围", required = false)
})
public class SceneVecServiceOutOperator extends StpOperatorHelper {
    static final String LAYER_TEMPLATE_URL = "{}/mapserver/vmap/{}/getMap?styleId={}&x={x}&y={y}&l={z}&tilesize=512";

    @InputParams({
            @InputParam(ref = "serverUrl", name = "空服地址", desc = "空服地址，如: http://192.168.164.45:8021", required = true),
            @InputParam(ref = "serverName", name = "服务名称", desc = "服务名称, 矢量瓦片服务的名称", required = true),
            @InputParam(ref = "styleId", name = "样式ID", desc = "样式ID, 矢量瓦片服务的样式ID", required = true),
            @InputParam(ref = "bbox", name = "四至范围", desc = "四至范围，xmin,ymin,xmax,ymax", required = false),
    })
    public SceneVecServiceOutOperator() {
    }

    public static void main(String[] args) throws Exception {
        OperatorTestBuild.execute(SceneVecServiceOutOperator.class, TestParamBuilder.aBuilder()
                .param("dataId", "test")
                .param("tableName", "table")
                .build());
    }

    @Override
    public void execute(ParamTool paramTool) throws Exception {
        String serverUrl = paramTool.getStr("serverUrl");
        String serverName = paramTool.getStr("serverName");
        String styleId = paramTool.getStr("styleId");

        String vmap_url = StrUtil.format(LAYER_TEMPLATE_URL, serverUrl, serverName, styleId);
        this.result("vmap_url", vmap_url);
        this.result("bbox", paramTool.getStr("bbox"));
    }
}
